package com.brspace.qualitycontrol.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.brspace.qualitycontrol.entity.RolePermissionRelation;
import com.brspace.qualitycontrol.entity.vo.PerAddRoleVo;
import com.brspace.qualitycontrol.mapper.RolePermissionRelationMapper;
import com.brspace.qualitycontrol.service.RolePermissionRelationService;
import com.brspace.qualitycontrol.utils.EmptyUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 角色和权限关联表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-04-21
 */
@Service
public class RolePermissionRelationServiceImpl extends ServiceImpl<RolePermissionRelationMapper, RolePermissionRelation> implements RolePermissionRelationService {
    @Resource
    private RolePermissionRelationMapper rolePerMapper;
    /**
     * 给角色分配权限
     * @Author: wangt
     * @Date: 2021-04-21 09:59:29
     */
    @Override
    public void add(PerAddRoleVo perAddRoleVo) {
        if (EmptyUtil.isNotEmpty(perAddRoleVo)) {
            throw new SecurityException("参数异常！");
        }
        rolePerMapper.deleteById(perAddRoleVo.getRoleId());
        for (Integer integer : perAddRoleVo.getPermissinId()) {
            RolePermissionRelation rolePer = new RolePermissionRelation();
            rolePer.setRoleId(perAddRoleVo.getRoleId());
            rolePer.setPermissinId(integer);
            rolePerMapper.insert(rolePer);
        }
    }
}
